
$(function(){
    var cwxtzhys = {
        grid:$("#cwxtzhys_grid"),
        gridOptions:{
            url:$.webPath() + "/cwgl/kmys/cwxtzhys/cwxtzhysList",
            toolbar:'#toolbar_cwxtzhys',
            fitColumns:true,
            fit:true,
            rownumbers:true,
            pagination:true,
            pageNumber: 1,
            singleSelect:true,
            columns:[
                [
                    {field:'yg.xm',title:'姓名',width:100},
                    {field:'zgjgJc',title:'主管机构',width:100},
                    {field:'yg.jqdlm',title:"财务系统登录名",editor:{type:'text'},width:100},
                    {field:'yg.jqdlmm',title:"财务系统登录密码",editor:{type:'text'},width:100},
                    {field:'cz',title:'操作',formatter:function(value,row,index){
                        if(value && value == 'save')
                            return '<a index="'+index+'" name="save" href="javascript:void(0)" onclick="save_cwxtzhys('+index+')"></a>'
                        return '<a index="'+index+'" name="edit" href="javascript:void(0)" onclick="edit_cwxtzhys('+index+')"></a>'
                    },width:30,align:'center'}
                ]
            ],
            onLoadSuccess:function(){
                $("a[name='edit']").linkbutton({
                    plain:true,
                    iconCls:'icon-edit'
                });
                $("a[name='save']").linkbutton({
                    plain:true,
                    iconCls:'icon-save'
                });
            },
            onBeforeEdit:function(rowIndex, rowData){
                cwxtzhys.grid.edatagrid("updateRow",{
                    index: rowIndex,
                    row:$.extend({},rowData,{cz:'save'})

                });
                $("a[name='save']").linkbutton({
                    plain:true,
                    iconCls:'icon-save'
                });
            },
            onAfterEdit: function (index, row) {
                var url = $.webPath() +'/cwgl/kmys/cwxtzhys/save';
                $.post(url, row, function (data) {
                    if(data.statusCode == 200){
                        cwxtzhys.grid.datagrid('updateRow', {
                            index: index,
                            row:$.extend({},row,{cz:'edit'})
                        });
                        $("a[name='edit']").linkbutton({
                            plain:true,
                            iconCls:'icon-edit'
                        });
                    } else {
                        $.messager.alert('info',data.message);
                        cwxtzhys.grid.edatagrid("beginEdit",index);
                    }
                }, 'json');
            }
        },
//        save:function(){},
        search:function(){
            cwxtzhys.grid.datagrid("load",{
                xm:$("#cwxtzhys_xm").val() || '',
                nbgsId:$("#cwxtzhys_nbgs").combobox("getValue") || ''
            });
        }
    }
    cwxtzhys.grid.edatagrid(cwxtzhys.gridOptions);
    $("#cwxtzhys_nbgs").gsjgtree(1);
    $("#btn_cwxtzhys_search").click(function(){
        cwxtzhys.search();
    });
});
function save_cwxtzhys(index){
    $("#cwxtzhys_grid").edatagrid("endEdit",index);
}
function edit_cwxtzhys(index){
    $("#cwxtzhys_grid").edatagrid("beginEdit",index);
}